import { createSlice, PayloadAction } from "@reduxjs/toolkit"
import { rootState } from "./index"
//这个用于声明状态的类型
export interface CounterState {
    value: number;
    status: string
}
//这个用于声明初始状态
const initialState: CounterState = {
    value: 0,
    status: 'idle'
}
export const counterSlice = createSlice({
    name: 'counter',//切片的名称
    initialState,//初始状态
    reducers: {
        increment: (state, payload: PayloadAction<number>) => {
            state.value = state.value + 1
        }
    }
})

export const { increment } = counterSlice.actions

export const selectCount = (state: rootState) => state.counter.value

export default counterSlice.reducer